package com.example.btnapplication;

import java.util.ArrayList;

import android.R.integer;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class GuidViewPagerAdapter extends PagerAdapter implements
		OnPageChangeListener {

	ArrayList<ImageView> mImageViews;
	private LinearLayout guidLinearLayout;
	private ArrayList<View> pointList;
	public GuidViewPagerAdapter(ArrayList<ImageView> ImageViews,LinearLayout guidLinearLayout,ArrayList<View> pointList ) {
		this.mImageViews = ImageViews;
		this.guidLinearLayout =guidLinearLayout;
		this.pointList =pointList;
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		ImageView childImageView = mImageViews.get(position);
		container.addView(childImageView);
		return childImageView;
	}

	@Override
	public int getCount() {
		return mImageViews.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == arg1;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		ImageView childImageView = mImageViews.get(position);
		container.removeView(childImageView);
	}
	// OnPageChangeListener
	@Override
	public void onPageScrollStateChanged(int arg0) {

	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
	}

	@Override
	public void onPageSelected(int position) {
		int Childcount = guidLinearLayout.getChildCount();
		 Log.d("count", Childcount+"");
		 for (int index = 1; index <= Childcount; index++) {
		    View view =  pointList.get((index-1));
			 if (position==(index-1)) {
				 Log.d("positionchange", position+"");
				 view.setBackgroundResource(R.drawable.bg_point_selected);
			 }else {
				 view.setBackgroundResource(R.drawable.bg_point);
			}
		}
	}
}
